{% extends "main/base.html" %}
{% load i18n static main_tag %}
{% block title %}{% trans '设备库存' %}{% endblock %}
{% block this_css %}
<link rel="stylesheet" type="text/css" href="{% static 'flatlab/css/bootstrap-select.min.css' %}">
{% endblock %}
{% block content %}
<section class="panel">
    <div class="panel-body">
        <div class="col-md-9">
            <form class="form-inline" role="form" method="get">
                <div class="form-group">
                    <select name="c" class="selectpicker show-tick form-control" data-live-search="true">
                        <option value="">{% trans '所有仓库' %}</option>
                        {% for ss in warehouse_ls %}
                            {% if ss.pk|floatformat:'0' == request.GET.c|floatformat:'0' %}
                            <option value="{{ ss.pk }}" selected>{{ ss }}</option>
                            {% else %}
                            <option value="{{ ss.pk }}" >{{ ss }}</option>
                            {% endif %}
                        {% endfor %}
                    </select>
                </div>
                <div class="form-group">
                    <select name="d" class="selectpicker show-tick form-control" data-live-search="true">
                        <option value="">{% trans '所有归类' %}</option>
                        {% for ss in type_categories %}
                            {% if ss.pk|floatformat:'0' == request.GET.d|floatformat:'0' %}
                            <option value="{{ ss.pk }}" selected>{{ ss }}</option>
                            {% else %}
                            <option value="{{ ss.pk }}" >{{ ss }}</option>
                            {% endif %}
                        {% endfor %}
                    </select>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <input class="form-control" type="text" name="q" placeholder="" value="{% if request.GET.q %}{{ request.GET.q }}{% endif %}">
                        <span class="input-group-btn"><button class="btn btn-primary" type="submit">搜索</button></span>
                    </div>
                </div>
            </form>
        </div>
        <div class="col-md-3" align="right">
            {% if perms.main.add_equipmentin %}<a href="{% url 'main:equipment_in_create' %}?next={{ request.path }}"><button type="button" class="btn btn-success">{% trans "设备入库" %}</button></a>{% endif %}
            {% if perms.main.add_equipmentout %}<a href="{% url 'main:equipment_out_create' %}?next={{ request.path }}"><button type="button" class="btn btn-danger">{% trans "设备出库" %}</button></a>{% endif %}
        </div>
    </div>
</section>
<section class="panel">
    {% get_current_language as LANGUAGE_CODE %}
    <div class="table-responsive panel-body">
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>{% trans '设备编号' %}</th>
                    <th>{% trans '设备中文名' %}</th>
                    <th>{% trans '设备英文名' %}</th>
                    <th>{% trans '设备类型' %}</th>{% if perms.main.view_equipment_basic_price %}
                    <th>{% trans '价格' %}</th>{% endif %}
                    <th>{% trans '入库数量' %}</th>
                    <th>{% trans '出库数量' %}</th>
                    <th>{% trans '当前库存' %}</th>
            </thead>
            <tbody>{% for d in page_obj %}
                <tr>
                    <td>{{ d.equipment.pk }}</td>
                    <td><a href="{% url 'main:equipment_detail' d.equipment.id %}" target="_blank">{{ d.equipment.equipment_code }}</a></td>
                    <td>{{ d.equipment.equipment_cn }}</td>
                    <td>{{ d.equipment.equipment_en }}</td>
                    <td>{{ d.equipment.equipment_type }}</td>{% if perms.main.view_equipment_basic_price %}
                    <td>{{ d.equipment.basic_price }} RMB</td>{% endif %}
                    <td>{{ d.total_in }}</td>
                    <td>{{ d.total_out }}</td>
                    <td>{% for k, v in d.equipment.amount_left.items %}{{ k }} {{ v }}<br> {% endfor %}</td>
                </tr>{% endfor %}
            </tbody>
        </table>
        <div align="right">
            {% include 'main/tablenav.html' %}
        </div>
    </div>
</section>
{% endblock %}
{% block this_js %}
<script type="text/javascript" src="{% static 'flatlab/js/bootstrap-select.min.js' %}"></script>
{% endblock %}